package com.nd.mobile.study.common.exception;

import org.json.JSONException;
import org.json.JSONObject;

public class LogicException extends Exception {

	private static final long	serialVersionUID	= -4058921456405000232L;
	private Exception			inner;
	private JSONObject			errorObj;

	public LogicException(String exceptionCode, Exception innerException) {
		super(exceptionCode);
		inner = innerException;
	}

	public LogicException(String exceptionCode, JSONObject errorObj) {
		super(exceptionCode);
		this.errorObj = errorObj;
	}

	public JSONObject getError() {
		return errorObj;
	}

	public Exception InnerException() {
		return inner;
	}

	@Override
	public String getMessage() {
		if (errorObj != null) {
			try {
				return errorObj.getString("error");
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		return inner.getMessage();
	}
}
